from django.shortcuts import render
from django.utils import timezone
from blog.models import Visitors


def index(request):
    time_now = timezone.now()
    try:
        visitor = Visitors.objects.filter(create_time=time_now).first()
        if not visitor:
            visitor = Visitors()
            visitor.visitors = 1
            visitor.save()
        else:
            visitor.visitors += 1
            visitor.save()
    except Exception as e:
        print(e.args)
    return render(request, 'background/index.html')
